var path="http://localhost:8081";

var app = angular.module('myApp', []);
app.config(function($httpProvider){
	$httpProvider.interceptors.push(function ($q, $rootScope) {
        return {
            'request': function(config) {
            	var authToken = sessionStorage.authToken;
                if (!!authToken) {
                	config.headers['Content-Type'] = "application/x-www-form-urlencoded";
                    config.headers['X-Auth-Token'] = authToken;
                } 
                console.log(config)
                return config || $q.when(config);
            }
        };
    }
);
});

app.controller('appCtrl', function($scope, $http,$window) {
  $http.get('http://localhost:9908/index').success(function (response) {
		if("/login.html"==response){
			  window.location = response;
		  }
	});
  
  $scope.logout = function(){
	  sessionStorage.authToken="";
	  $window.location.reload();
  }
});

app.controller('submitForm', function($scope, $http) {
	$scope.confirm = function(){
		$http({
	    	  url:'http://localhost:9908/login?username='+$scope.username+"&password="+$scope.password+"&_csrf=7f5afe59-21a5-4723-b65b-64feaa2f4b92",
	    	  method:"POST",
	    	  data: {username: $scope.username,password: $scope.password}
	    }).success(function (response) {
	    	sessionStorage.authToken=response.token;
	    	window.location = response.rstUrl;
	    }).error(function(response) {
		　　	console.log(response)
	　　	});
    };
    
});